home *** CD-ROM | disk | FTP | other *** search
/ Programmer Power Tools / Programmer Power Tools.iso / asmutl / testnmi.asm < prev    next >
Assembly Source File  |  1985-01-06  |  3KB  |  76 lines

  1. comment *    TEST_NMI     Copyright (c) 1984 by Lawrence B. Afrin
  2.  
  3.         TEST_NMI is a demonstration program that shows how
  4.         an NMI interrupt is somehow (?) invoked when NMI
  5.         interrupts are enabled after having been disabled on
  6.         the IBM PC.  This source code should be run through
  7.         the assembler, the linker, and finally EXE2BIN.  Then,
  8.         when it is run, the user will see a capital letter A
  9.         show up in the first column of roughly the fifth line
  10.         of the monochrome video screen.  This shows that the
  11.         NMI interrupt routine was invoked.  This program was
  12.         developed on one of the original (1981) models of the
  13.         IBM PC.  I do not know whether this "bug" exists on
  14.         later models.  -- LBA, 12/30/84
  15. *
  16.  
  17. biosseg    segment    at 0
  18.     org    2h*4        ; locate the address of the NMI interrupt
  19. int_2    label    dword        ; vector
  20. biosseg    ends
  21.  
  22. cseg    segment
  23.     assume    cs:cseg
  24.     org    100h        ; this will be a .COM file
  25.  
  26. doit    proc    near
  27.     jmp    start        ; jump around new NMI interrupt handler
  28.  
  29. new_nmi:    push    bx        ; set up to address monochrome video
  30.     push    es        ; screen memory at segment B000 hex
  31.     mov    bx,0b000h
  32.     mov    es,bx
  33.     mov    bx,80*2*5    ; set up to address line 5, column 1
  34.     mov    byte ptr es:[bx],'A'    ; display an 'A' there
  35.     pop    es        ; exit from this interrupt "handler"
  36.     pop    bx
  37.     iret
  38.  
  39.     assume    ds:biosseg    ; code to install new NMI handler:
  40.  
  41. start:    mov    ax,biosseg    ; set up to address interrupt vector area
  42.     mov    ds,ax
  43.  
  44. ; NOTE: The following two instructions are the real kicker to this
  45. ; program.  As noted above in the header comments, it is the re-
  46. ; enabling of the NMI interrupts FOLLOWING THE DISABLING OF THEM
  47. ; that causes the spurious NMI interrupt to be signalled.  If we were
  48. ; to remove the following two instructions, then the re-enabling
  49. ; of an already enabled NMI interrupt would have no effect.
  50.  
  51.     mov    al,00        ; temporarily mask off NMI interrupts
  52.     out    0a0h,al
  53.     mov    word ptr int_2,offset new_nmi    ; set up address of new NMI
  54.     mov    int_2[2],cs            ; interrupt handler routine
  55.  
  56. ; NOTE: This is where the funny business happens.  The IBM PC Technical
  57. ; Reference Manual says that to enable NMI interrupts, an 80 hex should
  58. ; be output to port A0 hex.  The manual doesn't give any indication that
  59. ; this operation provokes the system into signalling an NMI interrupt,
  60. ; but that is indeed what appears to happen when the following OUT
  61. ; instruction is executed.
  62.  
  63.     mov    al,80h    ; turn NMI interrupts back on
  64.     out    0a0h,al
  65.  
  66.     mov    dx,offset start    ; if we get here (fat chance),
  67.     int    27h            ; exit and leave new NMI handler
  68.                     ; resident
  69.  
  70. doit    endp
  71.  
  72. cseg    ends
  73.  
  74.     end    doit
  75.  
  76.